package com.zjw.zy.ext

import com.zjw.zy.utils.LogUtils
import com.zjw.zy.utils.ResourcesUtils
import com.zjw.zy.utils.ToastUtils

/**
 * @author     ：zhong.jw
 * @date       ：Created in 2022/9/28 10:52
 * @description：
 */


fun String.logD(tag: String) {
    safeCall {
        LogUtils.d(tag, this)
    }
}

fun String.logI(tag: String) {
    safeCall {
        LogUtils.i(tag, this)
    }
}

fun String.logE(tag: String) {
    safeCall {
        LogUtils.e(tag, this)
    }
}

fun Int.longToast() {
    safeCall {
        ToastUtils.showLong(ResourcesUtils.getString(this))
    }
}

fun Int.shortToast() {
    safeCall {
        ToastUtils.showShort(ResourcesUtils.getString(this))
    }
}

fun String.longToast() {
    safeCall {
        ToastUtils.showLong(this)
    }
}


fun String.shortToast() {
    safeCall {
        ToastUtils.showShort(this)
    }
}


private fun safeCall(task: () -> Unit) {
    try {
        task()
    } catch (ignore: Throwable) {
    }
}